<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue';

defineOptions({
  name: "Welcome"
});

// 创建响应式时间变量
const currentTime = ref(new Date().toLocaleString());

// 时间更新定时器引用
let timer: number | null = null;

// 更新时间的函数
const updateTime = () => {
  currentTime.value = new Date().toLocaleString();
};

// 组件挂载时设置定时器
onMounted(() => {
  // 立即执行一次
  updateTime();
  // 每秒更新一次时间
  timer = window.setInterval(updateTime, 1000);
});

// 组件卸载时清除定时器
onUnmounted(() => {
  if (timer !== null) {
    clearInterval(timer);
    timer = null;
  }
});

// 呼叫管家功能
const callButler = () => {
  alert("正在呼叫管家，请稍候...");
};

// 一键保修功能
const submitRepair = () => {
  alert("正在提交保修申请，请稍候...");
};

// 投诉建议功能
const submitFeedback = () => {
  alert("正在提交投诉建议，请稍候...");
};

// 紧急求助功能
const emergencyHelp = () => {
  alert("紧急求助已发送，工作人员将尽快联系您！");
};
</script>

<template>
  <div class="welcome-container">
    <div class="welcome-header">
      <h1>公寓信息发布系统</h1>
      <h2>欢迎使用</h2>
      <h3>当前版本：1.0.0</h3>
      <h3>当前时间：{{ currentTime }}</h3>
    </div>
    
    <div class="service-buttons">
      <div class="button-row">
        <button class="service-button" @click="callButler">
          <div class="button-icon">📞</div>
          <div class="button-text">呼叫管家</div>
        </button>
        
        <button class="service-button" @click="submitRepair">
          <div class="button-icon">🔧</div>
          <div class="button-text">一键保修</div>
        </button>
      </div>
      
      <div class="button-row">
        <button class="service-button" @click="submitFeedback">
          <div class="button-icon">📝</div>
          <div class="button-text">投诉建议</div>
        </button>
        
        <button class="service-button emergency" @click="emergencyHelp">
          <div class="button-icon">🆘</div>
          <div class="button-text">紧急求助</div>
        </button>
      </div>
    </div>
  </div>
</template>

<style scoped>
.welcome-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}

.welcome-header {
  margin-bottom: 40px;
}

.service-buttons {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.button-row {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.service-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 150px;
  height: 150px;
  border-radius: 10px;
  border: none;
  background-color: #f0f2f5;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.service-button:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.button-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

.button-text {
  font-size: 18px;
  font-weight: bold;
}

.emergency {
  background-color: #fff2f0;
}

.emergency:hover {
  background-color: #ffccc7;
}
</style>
